﻿<?=$this->load->view('include_header',null)?>
	<div id="top-panel">
		<div id="panel">
			<ul>
				<li class="current"><a href="<?=site_url('archive/idcard/'.$id)?>" class="report"><?=(empty($id))?"录入新":"编辑"?>客户基本信息</a></li>
				
			</ul>
		</div>
	</div>
	<div id="wrapper">
		<div id="content">
			<div id="box">
			<form id="form" method="POST" action="<?=site_url('archive/residency_update/'.$cateid)?>">
			<fieldset>
			<legend>户口本 Household Register(Hukou Book)</legend>
			<table width="100%">
				<tr><td colspan="5" align="center"><h3>人数统计 Headcount</h3></td></tr>
				<tr>
					<td><strong>地址 Address</strong></td>
					<td colspan="4"><input name="hc_address" type="text" value="<?=@$info->hc_address?>" size="60" /></td>
					</tr>
				<tr>
					<td width="150"><strong>家庭构成 Family Compostion</strong></td>
					<td width="120"><strong>姓名 Full Name</strong></td>
					<td width="80"><strong>性别 Sex</strong></td>
					<td width="120"><strong>身份证号码 National ID Number</strong></td>
					<td><strong>备注 Notes</strong></td>
				</tr>
				<?php
				$persons = json_decode(@$info->hc_persons);
				if ( !empty($persons) ):
					foreach( $persons as $val): 
				?>
				<tr>
					<td><?=$val->name?></td>
					<td><?=$val->relation?></td>
					<td><?=($val->sex==1)?'Male':'Female'?></td>
					<td><?=$val->idcard?></td>
					<td>&nbsp;</td>
				</tr>
				<?php
					endforeach;
					endif;
				?>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td colspan="5">Description: The new booklet has been logged for  18-bit numbers, not to print this table</td>					</tr>
				<tr>
					<td colspan="3"><strong>承办人 Issuer:</strong>
						<input type="text" name="hc_issued_person" value="<?=@$info->hc_issued_person?>" /></td>
					<td colspan="2"><strong>登记日期 Date Of Issued:</strong>
						<input type="text" name="hc_issued_date" id="hc_issued_date" value="<?=@$info->hc_issued_date?>" /></td>
					</tr>
			</table>
			<br />
			
			<table width="100%">
                <tr><td colspan="4" align="left"><b>请从这开始填写　Please fill from here</b></td></tr> 
				<tr><td colspan="4" align="center"><h3>户口本 Household Register(Hukou Book)</h3></td></tr>
				<tr>
					<td width="90"><strong>户别 Hukou Type</strong></td>
					<td><select name="hh_category" style="background:#FFFFC0"/>
                        <option value=''>-</option>
                        <option value='Non-Agricultural' <?if(@$info->hh_category=='Non-Agricultural') echo "selected";?>>非农业-Non-Agricultural</option>  
                        <option value='Collective' <?if(@$info->hh_category=='Collective') echo "selected";?>>集体-Collective</option>  
                        <option value='Agricultural' <?if(@$info->hh_category=='Agricultural') echo "selected";?>>农业-Agricultural</option>  
                    </select></td>
					<td width="50"><strong>户主姓名 Full Name of Householder</strong></td>
					<td><input type="text" name="hh_name" id="hh_name" value="<?=@$info->hh_name?>" /></td>
				</tr>
				<tr>
					<td><strong>户号 Hukou No.</strong></td>
					<td><input type="text" name="hh_hukou_no" id="hh_hukou_no" value="<?=@$info->hh_hukou_no?>" /></td>
					<td><strong>住址 Address</strong></td>
					<td><input type="text" name="hh_hukou_address" value="<?=@$info->hh_hukou_address?>" /></td>
					</tr>
				<tr>
					<td colspan="4">
					<p>省级公安机关户口专用章 The special seal of Registered Permanent Residence of Public Security  Office of 
						<input type="text" name="hh_province" value="<?=@$info->hh_province?>" />.<br />
						户口登记机关户口专用章 The special seal of Registered  Permanent Residence of 
						<input type="text" name="hh_station" value="<?=@$info->hh_station?>" />. <br />
					</p>
					</td>
				</tr>
				<tr>
					<td colspan="2"><strong>承办人 Issuer</strong>: 
						<input type="text" name="hh_issued_person" value="<?=@$info->hh_issued_person?>" /></td>
					<td colspan="2"><strong>登记日期 Date Of Issued</strong>:
						<input type="text" name="hh_issued_date" id="hh_issued_date" value="<?=@$info->hh_issued_date?>" /></td>
					</tr>
			</table>
			<br />
			<div id="bl">

			</div>
			
			<input type="hidden" name="hc_persons" id="hc_persons" value="<?=@$info->hc_persons?>" />
			<input type="hidden" name="cards" id="cards" value="<?=@$info->cards?>" />
			<input type="hidden" name="id" value="<?=$id?>" />
			<input type="button" id="button1" value="增加一张户口卡片 Add more information page" />
			<input type="button" id="button2" value="保存所有户口信息 Save family member's inforamtion" />
			</fieldset>
			</form>
			</div>

		</div>
        
        <script type="text/javascript" src="js/jquery.autocomplete.pack.js"></script>
        <link type="text/css" rel="stylesheet" href="css/jquery.autocomplete.css"/>
        
		<?=$this->load->view('include_sidebar',array('id'=>$id,'forms'=>$forms))?>
	</div>

	<script type="text/javascript">

	$(document).ready(function(){

        $.datepicker.setDefaults(
            {
            dateFormat: 'dd/mm/yy',
            readOnly: false
            }
        );
        
		$( "#hc_issued_date" ).datepicker({
			changeMonth: true,
			changeYear: true,
			showOn: "both",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true
		});
		$( "#hh_issued_date" ).datepicker({
			changeMonth: true,
			changeYear: true,
			showOn: "both",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true
		});

		
		$("#button1").click( function() {
			writeTag(true);
		});

        var card_index = 1 ; // 标识户口卡的张数  
                    
		$("#button2").click(function() {
			if( $.trim($("#hh_name").val())=="" ){
				alert('户主不能为空');
				$("#hh_name").focus();
				return false;
			}
			
			if( $.trim($("#hh_hukou_no").val())=="" ){
				alert('户籍号码不能为空');
				$("#hh_hukou_no").focus();
				return false;
			}
            
            if(convert_to_date($('#hc_issued_date').val()).getTime() >  new Date().getTime()) {
                alert('[登记日期]不能大于[当前日期]！');
                $('#hc_issued_date').focus();     
                return false;
            }  
             
            if(convert_to_date($('#hh_issued_date').val()).getTime() > new Date().getTime()) {
                alert('[登记日期]不能大于[当前日期]！'); 
                $('#hh_issued_date').focus();
                return false;
            } 
        
			var persons = [];
			var cards = [];
			var cardcheck = true;
            card_index = 1;
			$("table:.jobline").each(function(){
			    //alert( $(this).find("input[type='radio'][name^='sex']:checked").val() );
				//$("input[type='radio'][name^='sex']").eq(1).attr("checked", true);
				//$(this).find("input[type='radio'][name^='sex'][value='1']").attr("checked","true"); 
				
				if( $.trim( $(this).find("#name").val() )=="" ){
					alert('姓名不能为空');
					$(this).find("#name").focus();
					cardcheck=false;
					return false;
				}
				
				if( $(this).find("input[type='radio'][name^='sex']:checked").val()==undefined ){
					alert('请选择性别');
					$(this).find("input[type='radio'][name^='sex']").eq(0).focus();
					cardcheck=false;
					return false;
				}
				
				if( $.trim( $(this).find("#idcard").val() )=="" ){
					alert('身份证号码不能为空');
					$(this).find("#idcard").focus();
					cardcheck=false;
					return false;
				}
				
				persons.push( {
					name:$(this).find("#name").val(), 
					relation:$(this).find("#relation").val(), 
					sex:$(this).find("input[type='radio'][name^='sex']:checked").val(),
					idcard:$(this).find("#idcard").val() 
				});
				cards.push( {
					name:$(this).find("#name").val(), 
					relation:$(this).find("#relation").val(), 
					another_name:$(this).find("#another_name").val(), 
					sex:$(this).find("input[type='radio'][name^='sex']:checked").val(),
					born:$(this).find("#born").val(),
					race:$(this).find("#race").val(),
					native:$(this).find("#native").val(),
					birth:$(this).find("#birth_"+card_index).val(),
					another_address:$(this).find("#another_address").val(),
					faith:$(this).find("#faith").val(),
					idcard:$(this).find("#idcard").val(),
					height:$(this).find("#height").val(),
					blood:$(this).find("#blood").val(),
					education:$(this).find("#education").val(),
					marital:$(this).find("#marital").val(),
					service:$(this).find("#service").val(),
					employer:$(this).find("#employer").val(),
					profession:$(this).find("#profession").val(),
					coming_from:$(this).find("#coming_from").val(),
					coming_to:$(this).find("#coming_to").val(),
					issued_person:$(this).find("#issued_person").val(),
					issued_date:$(this).find("#issued_date_"+card_index).val()
				});
                card_index++;  
			});
			if (!cardcheck) return false;
			//alert(JSON.stringify(persons));
			//alert(JSON.stringify(cards));
			$("#hc_persons").val(JSON.stringify(persons));
			$("#cards").val(JSON.stringify(cards));
			
			$("#bl").remove();
			$("#form").submit();
		});
		
		var inits = <?=empty($info->cards)?"undefined":@$info->cards?>;
		if(inits==undefined){
			writeTag(false);
		}else{
            card_index = 1;   
			$.each( inits, function(i, n){
				//alert( "Name: " + i + ", Value: " + n );
				writeTag(true);
				$("table:.jobline:last").find("#name").val(n.name);
				$("table:.jobline:last").find("#relation").val(n.relation);
				$("table:.jobline:last").find("#another_name").val(n.another_name);
				$("table:.jobline:last").find("input[type='radio'][name^='sex'][value='"+n.sex+"']").attr("checked","true"); 
				$("table:.jobline:last").find("#born").val(n.born);
				$("table:.jobline:last").find("#race").val(n.race);
				$("table:.jobline:last").find("#native").val(n.native);
				$("table:.jobline:last").find("#birth_"+card_index).val(n.birth);
				$("table:.jobline:last").find("#another_address").val(n.another_address);
				$("table:.jobline:last").find("#faith").val(n.faith);
				$("table:.jobline:last").find("#idcard").val(n.idcard);
				$("table:.jobline:last").find("#height").val(n.height);
				$("table:.jobline:last").find("#blood").val(n.blood);
				$("table:.jobline:last").find("#education").val(n.education);
				$("table:.jobline:last").find("#marital").val(n.marital);
				$("table:.jobline:last").find("#service").val(n.service);
				$("table:.jobline:last").find("#employer").val(n.employer);
				$("table:.jobline:last").find("#profession").val(n.profession);
				$("table:.jobline:last").find("#coming_from").val(n.coming_from);
				$("table:.jobline:last").find("#coming_to").val(n.coming_to);
				$("table:.jobline:last").find("#issued_person").val(n.issued_person);
				$("table:.jobline:last").find("#issued_date_"+card_index).val(n.issued_date);
                card_index++;
			});
		}
	});
	
	var seq = 1;
	function writeTag( removeable ){
		var str="";
		str+='<table width="100%" class="jobline">'
		str+='<tr><td colspan="6" align="center"><h3>常住人口登记卡 Information Page</h3></td></tr>'
		str+='<tr><td><strong>姓名 Full Name</strong></td>'
		str+='<td colspan="2"><input type="text" name="name" id="name" /></td>'
		str+='<td><strong>户主或与户主关系 Relationship with Householder</strong></td>'
		str+='<td colspan="2"><input type="text" name="relation" id="relation" /></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>曾用名 Other Names Used</strong></td>'
		str+='<td colspan="2"><input type="text" name="another_name" id="another_name" /></td>'
		str+='<td><strong>性别 Sex</strong></td>'
		str+='<td colspan="2"><input type="radio" name="sex'+seq+'" value="1" />Male  <input type="radio" name="sex'+seq+'" value="2" />Female</td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>出生地 Place of Birth</strong></td>'
		str+='<td colspan="2"><input type="text" name="born" id="born" /></td>'
		str+='<td><strong>民族 Enthnic Group</strong></td>'
		str+='<td colspan="2"><select name="race" id="race" style="background:#FFFFC0"><?foreach($ethnic as $row) {echo "<option value=\"".$row->en_name."\">". substr($row->en_name, 0, 1) ."-".$row->cn_name."-[".$row->en_name."]</option>";}?></select></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>籍贯 Ancestral Home</strong></td>'
		str+='<td colspan="2"><input type="text" name="native" id="native" /></td>'
		str+='<td><strong>出生日期 Date of Birth</strong></td>'
		str+='<td colspan="2"><input type="text" name="birth" id="birth_'+seq+'" /></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>本市(县)其他住址 Other addresses</strong></td>'
		str+='<td colspan="2"><input type="text" name="another_address" id="another_address" /></td>'
		str+='<td><strong>宗教信仰 Religion</strong></td>'
		str+='<td colspan="2"><select name="faith" id="faith" style="background:#FFFFC0">'+get_select_options(faith_arr)+'</select></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>公民身份证件编号 National ID No.</strong></td>'
		str+='<td><input type="text" name="idcard" id="idcard" /></td>'
		str+='<td><strong>身高 Height</strong></td>'
		str+='<td><input name="height" id="height" type="text" size="8" /></td>'
		str+='<td><strong>血型 Blood Type</strong></td>'
		str+='<td><select name="blood" id="blood" type="text" style="background:#FFFFC0">'+get_select_options(blood_arr, 'only_display_key')+'</select></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>文化程度 Educational Qualification</strong></td>'
		str+='<td><select type="text" name="education" id="education" style="background:#FFFFC0">'+get_select_options(education_arr)+'</select></td>'
		str+='<td><strong>婚姻状况 Marital Status</strong></td>'
		str+='<td><select name="marital" id="marital" type="text" style="background:#FFFFC0">'+get_select_options(marital_arr)+'</select></td>'
		str+='<td><strong>兵役状况 National Service</strong></td>'
		str+='<td><select name="service" id="service" type="text"  style="background:#FFFFC0">'+get_select_options(service_arr)+'</select></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td><strong>服务处所 Employer</strong></td>'
		str+='<td colspan="2"><input type="text" name="employer" id="employer" /></td>'
		str+='<td><strong>职业 Profession</strong></td>'
		str+='<td colspan="2"><select type="text" name="profession" id="profession" style="background:#FFFFC0">'+get_select_options(profession_arr)+'</select></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td colspan="2"><strong>何时由何地迁来本市(县) Date of coming to this city</strong></td>'
		str+='<td colspan="4"><input name="coming_from" id="coming_from" type="text" size="50" /></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td colspan="2"><strong>何时由何地迁来本址 Date of coming to this address</strong></td>'
		str+='<td colspan="4"><input name="coming_to" id="coming_to" type="text" size="50" /></td>'
		str+='</tr>'
		str+='<tr>'
		str+='<td colspan="3"><strong>承办人 Issuer: </strong>'
		str+='<input type="text" name="issued_person" id="issued_person" /></td>'
		str+='<td colspan="3"><strong>登记日期 Date Of Issued: </strong>'
		str+='<input type="text" name="issued_date" id="issued_date_'+seq+'" /></td>'
		str+='</tr>'
		if (removeable) str+='<tr><td colspan="6"><input type="button" value=" 移除 " /></td></tr>';
		str+='</table>'
		
		$("#bl").append(str);
		
		if (removeable){ 
			$("table:.jobline:last").find("[type='button']").click( function() {
				$(this).parent().parent().parent().parent().remove();
			});
		}
        $( "#issued_date_"+seq ).datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: "both",
            buttonImage: "images/calendar.gif",
            buttonImageOnly: true
        });

         $( "#birth_"+seq ).datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: "both",
            buttonImage: "images/calendar.gif",
            buttonImageOnly: true
        });

                
        /*$("#race_"+seq).autocomplete("<?=base_url()?>user/quick_search_ethnic", {
            minChars: 0,
            width: 500,
            matchContains: "word",
            autoFill: false,
            formatItem: function(row, i, max) {
                var arr = (row+"").split(",");
                return i + "/" + max + ": " + arr[1] + '['+ arr[2] +']';
            },
            formatMatch: function(row, i, max) {
                return row;
            },
            formatResult: function(row) {
                var arr = (row+"").split(",");
                return arr[1];
            }
        });*/
        
        resize_parent_iframe();
         
		seq++;
	}
    

    var faith_arr = {
        'Bahai' : '巴哈伊教', 
        'Buddhism' : '佛教', 
        'Catholic' : '天主教', 
        'Christian' : '基督徒', 
        'Hindu' : '印度教', 
        'Islam' : '伊斯兰教', 
        'Others' : '其他', 
        'Atheist' : '无神论者'
    }

    var education_arr = {
        'Illiterate' : '不识字', 
        'Being Minor' : '学龄前儿童', 
        'Primary School' : '小学', 
        'Secondary School ' : '初中', 
        'High School' : '高中', 
        'Associate Degree' : '大学专科', 
        'Bachelor Degree' : '大学本科', 
        'Master Degree' : '硕士', 
        'Ph. D' : '博士'
    }
    
    var blood_arr = {
        'A' : 'A', 
        'B' : 'B', 
        'AB' : 'AB', 
        'O' : 'O'
    }
    
    var marital_arr = {
        'Married' : '已婚', 
        'Single' : '未婚',
        'Divorce' : '离异', 
        'Separated' : '分居', 
        'Widowed' : '鳏寡'  
    }
 
    var service_arr = {
        'Serviceman' : '现役', 
        'Ex-Serviceman' : '退役',
        'None' : '未服兵役'
    }
    
    var profession_arr = {
        'Businessman' : '商人',  
        'Company employee' : '公司职员',  
        'Teacher' : '教师',  
        'Student' : '学生',  
        'Housewife' : '家庭主妇',  
        'Unemployed' : '无业',  
        'Government official' : '政府官员',  
        'Staff of Media' : '新闻从业人员',  
        'Religious worker' : '宗教人士',  
        'Serviceman' : '现役军人',  
        'Retired' : '退休'
    }

    function get_select_options(kv) {
        var arr = [];
        arr.push('<option value="">-</option>');  
        for(var k in kv) {
            if(arguments.length == 1) {
                arr.push('<option value="'+k+'">'+kv[k]+'-'+k+'</option>');  
            } else {
                arr.push('<option value="'+k+'">'+kv[k]+'</option>');  
            }
           
        }
        return arr.join("");
    }
    
	</script>

	
<?=$this->load->view('include_footer',null)?>
